package com.dianrui.operation.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.dianrui.operation.R;
import com.dianrui.operation.bean.ChargeRecordList;
import com.dianrui.operation.view.MyListView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class PowerExchangeRecordAdapter extends BaseAdapter {

    Context context;
    List<ChargeRecordList> chargeRecordList;



    public PowerExchangeRecordAdapter(Context context, List<ChargeRecordList> chargeRecordList) {
        this.context = context;
        this.chargeRecordList = chargeRecordList;
    }

    public void refresh(List<ChargeRecordList> chargeRecordList) {
        this.chargeRecordList = chargeRecordList;
        this.notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return chargeRecordList.size();
    }

    @Override
    public Object getItem(int position) {
        return chargeRecordList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, final ViewGroup parent) {
        ViewHolder holder;
        if (convertView != null) {
            holder = (ViewHolder) convertView.getTag();
        } else {
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_exchangepower, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }
        if (chargeRecordList != null && chargeRecordList.size() > 0) {
            final ChargeRecordList chargeRecords = chargeRecordList.get(position);
            holder.dateTitle.setText(chargeRecords.date_title);
            final PowerExchangeListAdapter powerExchangeListAdapter=new PowerExchangeListAdapter(context);
            powerExchangeListAdapter.refresh(chargeRecords.data);
            holder.listView.setAdapter(powerExchangeListAdapter);


        }

        return convertView;
    }

    class ViewHolder {
        @BindView(R.id.date_title)
        TextView dateTitle;
        @BindView(R.id.listview)
        MyListView listView;


        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
